// g++ -std=c++11  -g -pthread -Wno-format -fpermissive -fopenmp -o test_4_18 test_4_18.cpp
// time ./test_4_18
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <omp.h>
#include <math.h>
#include <iostream>
using namespace std;

int iterater_num = 100000000, count = 0;
double x, y;

int main(int argc, char **argv) {

#if _OPENMP
        cout << " support openmp " << endl;
#else
        cout << " not support openmp" << endl;
#endif

#pragma omp parallel num_threads(8)
{
    unsigned seed = time(NULL);
    #pragma omp for private(x, y) reduction(+:count)
    for(int i = 0; i < iterater_num; i++) {
        x = (double)rand_r(&seed) / RAND_MAX;
        y = (double)rand_r(&seed) / RAND_MAX;
        if(x*x + y*y <= 1) {
            count++;
        }
    }
}
    printf("pi = %.10f\n",4.0*count/iterater_num);
    return 0;
}
